{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.0.0'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "tf.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "train, _ = tf.keras.datasets.fashion_mnist.load_data()\n",
    "images, labels = train\n",
    "x = images/255\n",
    "\n",
    "y=labels.astype(np.int32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "feature_columns = [tf.feature_column.numeric_column(\"x\", shape=[784])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_input_fn = tf.compat.v1.estimator.inputs.numpy_input_fn(x={\"x\":x},y=y,num_epochs=None,shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using default config.\n",
      "WARNING:tensorflow:Using temporary folder as model directory: /var/folders/95/7hxgmrh92z91hylbxw647jhr0000gn/T/tmp6z0vklae\n",
      "INFO:tensorflow:Using config: {'_model_dir': '/var/folders/95/7hxgmrh92z91hylbxw647jhr0000gn/T/tmp6z0vklae', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true\n",
      "graph_options {\n",
      "  rewrite_options {\n",
      "    meta_optimizer_iterations: ONE\n",
      "  }\n",
      "}\n",
      ", '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x1421edad0>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}\n"
     ]
    }
   ],
   "source": [
    "#classifier = tf.estimator.LinearClassifier(feature_columns=feature_columns, n_classes=10)\n",
    "\n",
    "classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns,hidden_units=[500, 500, 500], n_classes=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Calling model_fn.\n",
      "WARNING:tensorflow:Layer dnn is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2.  The layer has dtype float32 because it's dtype defaults to floatx.\n",
      "\n",
      "If you intended to run this layer in float32, you can safely ignore this warning. If in doubt, this warning is likely only an issue if you are porting a TensorFlow 1.X model to TensorFlow 2.\n",
      "\n",
      "To change all layers to have dtype float64 by default, call `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass dtype='float64' to the layer constructor. If you are the author of this layer, you can disable autocasting by passing autocast=False to the base Layer constructor.\n",
      "\n",
      "INFO:tensorflow:Done calling model_fn.\n",
      "INFO:tensorflow:Create CheckpointSaverHook.\n",
      "INFO:tensorflow:Graph was finalized.\n",
      "INFO:tensorflow:Running local_init_op.\n",
      "INFO:tensorflow:Done running local_init_op.\n",
      "INFO:tensorflow:Saving checkpoints for 0 into /var/folders/95/7hxgmrh92z91hylbxw647jhr0000gn/T/tmp6z0vklae/model.ckpt.\n",
      "INFO:tensorflow:loss = 2.3301134, step = 0\n",
      "INFO:tensorflow:global_step/sec: 54.1832\n",
      "INFO:tensorflow:loss = 1.9155712, step = 100 (1.847 sec)\n",
      "INFO:tensorflow:global_step/sec: 63.8656\n",
      "INFO:tensorflow:loss = 1.6000285, step = 200 (1.566 sec)\n",
      "INFO:tensorflow:global_step/sec: 61.9528\n",
      "INFO:tensorflow:loss = 1.3620818, step = 300 (1.614 sec)\n",
      "INFO:tensorflow:global_step/sec: 61.4397\n",
      "INFO:tensorflow:loss = 1.103858, step = 400 (1.628 sec)\n",
      "INFO:tensorflow:global_step/sec: 58.9006\n",
      "INFO:tensorflow:loss = 0.97635484, step = 500 (1.698 sec)\n",
      "INFO:tensorflow:global_step/sec: 56.3759\n",
      "INFO:tensorflow:loss = 0.9153143, step = 600 (1.774 sec)\n",
      "INFO:tensorflow:global_step/sec: 54.7716\n",
      "INFO:tensorflow:loss = 0.8850349, step = 700 (1.826 sec)\n",
      "INFO:tensorflow:global_step/sec: 55.4673\n",
      "INFO:tensorflow:loss = 0.82361245, step = 800 (1.803 sec)\n",
      "INFO:tensorflow:global_step/sec: 54.1423\n",
      "INFO:tensorflow:loss = 0.80772984, step = 900 (1.847 sec)\n",
      "INFO:tensorflow:global_step/sec: 54.2224\n",
      "INFO:tensorflow:loss = 0.7857527, step = 1000 (1.844 sec)\n",
      "INFO:tensorflow:global_step/sec: 52.4239\n",
      "INFO:tensorflow:loss = 0.7419777, step = 1100 (1.910 sec)\n",
      "INFO:tensorflow:global_step/sec: 51.6992\n",
      "INFO:tensorflow:loss = 0.76123935, step = 1200 (1.932 sec)\n",
      "INFO:tensorflow:global_step/sec: 52.5113\n",
      "INFO:tensorflow:loss = 0.7956954, step = 1300 (1.905 sec)\n",
      "INFO:tensorflow:global_step/sec: 45.7176\n",
      "INFO:tensorflow:loss = 0.80361784, step = 1400 (2.187 sec)\n",
      "INFO:tensorflow:global_step/sec: 48.2718\n",
      "INFO:tensorflow:loss = 0.8157842, step = 1500 (2.071 sec)\n",
      "INFO:tensorflow:global_step/sec: 49.2249\n",
      "INFO:tensorflow:loss = 0.6235721, step = 1600 (2.032 sec)\n",
      "INFO:tensorflow:global_step/sec: 50.3268\n",
      "INFO:tensorflow:loss = 0.64076, step = 1700 (1.987 sec)\n",
      "INFO:tensorflow:global_step/sec: 44.6981\n",
      "INFO:tensorflow:loss = 0.6687708, step = 1800 (2.237 sec)\n",
      "INFO:tensorflow:global_step/sec: 49.013\n",
      "INFO:tensorflow:loss = 0.5047634, step = 1900 (2.040 sec)\n",
      "INFO:tensorflow:Saving checkpoints for 2000 into /var/folders/95/7hxgmrh92z91hylbxw647jhr0000gn/T/tmp6z0vklae/model.ckpt.\n",
      "INFO:tensorflow:Loss for final step: 0.53016627.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow_estimator.python.estimator.canned.dnn.DNNClassifierV2 at 0x14228a590>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classifier.train(input_fn=train_input_fn, steps=2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
